import pandas as pd

# 读取词典文件
def read_dict(file_path, delimiter=' '):
    # 读取文件并只提取词汇列
    data = pd.read_csv(file_path, delimiter=delimiter, header=None, names=['词汇', '频率'], dtype=str)
    return set(data['词汇'].astype(str))

# 文件路径
dict1_path = 'dict/cn_dict.dat'  # 替换为第一个词典的文件路径
dict2_path = 'dict/filtered_dict.dat'  # 替换为第二个词典的文件路径

# 读取两个词典并获取词汇集合
dict1_words = read_dict(dict1_path, delimiter=' ')
dict2_words = read_dict(dict2_path, delimiter=' ')

# 合并两个词典的词汇集合并去除重复词
merged_words = dict1_words.union(dict2_words)

# 将结果保存到新的文件
with open('dict/merge_dict.dat', 'w', encoding='utf-8') as f:
    for word in sorted(merged_words):
        f.write(f"{word}\n")

print("词典合并完成，结果保存到 'dict/merge_dict.dat'")
